ACM ICPC::Regional Warmup 1 (Easy version) + Algunos cambios en el manual
[andmenj-acm.git] / 11436 - Cubes EXTREME! / j.3.cpp
blobd8271851c1c75e356743e36b7c8888799363afdd
1 #include<iostream>
2 #include<math.h>
3 #include <set>
5 using namespace std;
7 typedef unsigned long long ull;
9 inline ull cube(ull x){ return x*x*x; }
11 int main(){
12 ull n;
13 while(cin>>n &&n){
14 bool found = false;
15 for (ull k = 1; k*k<=n && k <= 29241; ++k){
16 if (n % k != 0 ||
17 3*k*k*k*k > 12*k*n){
18 continue;
20 ull y = ( -3*k*k + (ull)sqrt(12*k*n - 3*k*k*k*k) ) / (6*k);
21 if (y > 0 && cube(y+k) - cube(y) == n){
22 // cout << "k: " << k << endl;
23 cout << y + k << " " << y << endl;
24 found = true;
25 break;
27 /*if (k*k < n){
28 k = n/k;
29 ull y = ( -3*k*k + (ull)sqrt(12*k*n - 3*k*k*k*k) ) / (6*k);
30 if (y > 0 && cube(y+k) - cube(y) == n){
31 // cout << "k: " << k << endl;
32 cout << y + k << " " << y << endl;
33 found = true;
34 break;
36 k = n/k;
37 }*/
40 if (!found){
41 cout << "No solution" << endl;
44 return 0;